<style lang="sass" scoped>
	    .img{
        width:100px;
        height:100px;
    }
</style>
<template>
	<div class="container">
		<div class="search-cont">
			<el-input placeholder="输入信息检索" v-model="search.param">
				<i slot="prefix" class="el-input__icon el-icon-search"></i>
			</el-input>
			<el-button @click="getList()" type="primary" :plain="false">检索</el-button>
		</div>
		<div class="table-cont">
            <el-table :data="list" style="width: 100%">
                <el-table-column prop="account" label="用户名"></el-table-column>
                <el-table-column prop="userName" label="真实姓名"></el-table-column>
                <el-table-column prop="email" label="邮箱"></el-table-column>
                <el-table-column label="部门" width="200">
					<template slot-scope="scope">
                    	<p class='change-post' v-for='(item2,i2) in scope.row.deptAndPostBean'>
							{{item2.deptName}}
						</p>
                    </template>
				</el-table-column>
                <el-table-column label="职位">
					<template slot-scope="scope">
                    	<p v-for='(item2,i2) in scope.row.deptAndPostBean'>{{item2.postName}}</p>
                    </template>
				</el-table-column>
                <el-table-column prop="lastLoginTime" label="最后登录"></el-table-column>
                <el-table-column prop="loginCount" label="访问次数"></el-table-column>
                <el-table-column label="操作" width="180">
                    <template slot-scope="scope">
                    	<el-button type="primary" @click="routerGo('user_add',{type:'update',userId:scope.row.uid})">修改</el-button>
                    	<el-button @click="frozen(0,scope.row.account)" v-if='scope.row.isFree===0' type="primary">冻结</el-button>
                    	<el-button @click="frozen(1,scope.row.account)" v-else type="primary">解冻</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination background layout="prev, pager, next" :total="search.total" :page-size="search.pageSize" @current-change="handleCurrentChange">
            </el-pagination>
        </div>
	</div>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				search:{
					keyWord:'',
                    pageSize:config.pageSize,
                    page:1,
                    total:0,
				},
				list:[],
				dateValue:[]
			};
		},
		computed: {},
		watch:{
			'dateValue'(val){
				if(val.length>0){
					this.search.startTime = val[0];
					this.search.endTime = val[1];
				}else{
					this.search.startTime = '';
					this.search.endTime = '';
				}
			}
		},
		created() { 
		},
		mounted() {
			this.$nextTick(() => {
				this.getList();
			});
		},
		methods: {
			handleCurrentChange(val){
				this.search.pageNum = val;
				$('.container').scrollTop(0)
				this.getList();
			},
			getList(){
                let param = JSON.parse(JSON.stringify(this.search))
                util.ajax({
                    url:config.baseApi + 'bookMall-admin/api/admin/getUserListByPage',
                    data:util.objDislodge(param),
                    success:(data=>{
                        this.list = data.data.list;
                        this.search.total = data.data.totalNum;
                    })
                })
			},
			// 冻结 type1为冻结  2为解冻
            frozen(type,account){
                // this.showPagepop=true;
                var title='',
                    isFree=null;
                if(type===0){
                    title='是否冻结该用户？';
                    isFree=1;
                }else if(type===1){
                    title='是否解冻该用户？';
                    isFree=0;
                }
                popup.confirm({
                    content:title,
                    yes:()=>{
                        util.ajax({
                            url:config.baseApi+'bookMall-admin/api/admin/updateUserStatus',
                            data:{
                                isFree:isFree,
                                account:account
                            },
                            success:(data=>{
                                popup.miss({content:'操作成功！'});
                                this.getList();
                            })
                        })
                    }
                })
            },
		}
	};
</script>